﻿@model IEnumerable<WeProjectsModel.Document>

@{
    ViewBag.Title = "Files";
    int usrId = int.Parse(Membership.GetUser().ProviderUserKey.ToString());
}
@*@Html.Partial("_projectMenu")*@
<h2>@ViewBag.projectTitle > 项目文件</h2>

@using (Html.BeginForm("Upload", "Project", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <fieldset>
        <legend>选择上传文件</legend>
        <div>
            <input type="hidden" name="id" value=@Html.ViewContext.RouteData.Values["id"] />
            <input type="file" name="uploadFile" />
            <input type="submit" name="Submit" id="Submit" value="上传" />
        </div>
    </fieldset>
}
@if (Model.Count() > 0) { 
int rowNo = 0;
<table class="table">
    <tr>
        <th></th>
        <th>
            文件名
        </th>
        <th>
            文件大小（KB）
        </th>
        <th>
            上传时间
        </th>
        <th>
            上传人
        </th>@*
    <th>
        @Html.DisplayNameFor(model => model.ProjectID)
    </th>*@
        <th>操作</th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>@(++rowNo)</td>
        <td>
            @Html.DisplayFor(modelItem => item.Name)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Size)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.UploadDateTime)
        </td>
       <td>
            @Html.DisplayFor(modelItem => item.Member.DisplayName)
        </td>@*
    <td>
        @Html.DisplayFor(modelItem => item.ProjectID)
    </td>*@
        <td>
            @Html.ActionLink("下载", "DownloadFile", new { file = item.ID, project = item.ProjectID }, new { @class = "btn btn-success btn-small" })
@if (Roles.IsUserInRole("sysadmin") || ViewBag.projectOwnId == usrId || item.Member.ID==usrId ) {
            <span>&nbsp;</span>@Html.ActionLink("删除", "DeleteFile", new { file = item.ID, project = item.ProjectID }, new { @class = "btn btn-danger btn-small" })
}
        </td>
    </tr>
}
    <tr><td colspan="6">总共 @rowNo 条记录</td></tr>
</table>
}
else
{
    <b>暂无文件，请先添加。</b>
}
